package com.example.spring.source;

import cn.hutool.extra.spring.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

@Slf4j
public class SpringDemo {
    public static void main(String[] args) {
        // spring源码入口
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);
        Car car = (Car) applicationContext.getBean("car");
        car.setName("小狗");
        car.setAge(1);
        System.out.println(car.getName());

        Car car1;
        try {
            car1 = SpringUtils.getBean("car");
        } catch (Exception e) {
            log.info("异常");
            car1 = SpringUtil.getBean("car");
        }
        System.out.println(car1.getName());
    }
}
